﻿@inherits BaseItemComponent

<CascadingValue Value="this" IsFixed="true">
    @ChildContent
</CascadingValue>

@code {

    private IDictionary<string, object> label = new Dictionary<string, object>();
    private IDictionary<string, object> itemStyle = new Dictionary<string, object>();
    private IDictionary<string, object> lineStyle = new Dictionary<string, object>();
    private IDictionary<string, object> emphasis = new Dictionary<string, object>();
    private IDictionary<string, object> blur = new Dictionary<string, object>();
    private IDictionary<string, object> select = new Dictionary<string, object>();

    /// <summary>
    /// 指定设置的是桑基图哪一层，取值从 0 开始
    /// </summary>
    [Parameter]
    public int? depth { get; set; }

    protected override IDictionary<string, object> LoadSetting()
    {
        IDictionary<string, object>? setting = null;

        if (Base is Series scomponent)
        {
            scomponent.SetLevels((levels) =>
            {
                setting = levels;
            });
        }

        return setting ?? new Dictionary<string, object>();
    }

    public override void SetSetting(IDictionary<string, object> setting)
    {
        if (depth.HasValue)
            FillSetting("depth", depth.Value);
    }

    public void SetLabel(Action<IDictionary<string, object>> action)
    {
        FillSetting("label", label);
        action?.Invoke(label);
    }

    public void SetLineStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("lineStyle", lineStyle);
        action?.Invoke(lineStyle);
    }

    public void SetItemStyle(Action<IDictionary<string, object>> action)
    {
        FillSetting("itemStyle", itemStyle);
        action?.Invoke(itemStyle);
    }

    public void SetEmphasis(Action<IDictionary<string, object>> action)
    {
        FillSetting("emphasis", emphasis);
        action?.Invoke(emphasis);
    }

    public void SetBlur(Action<IDictionary<string, object>> action)
    {
        FillSetting("blur", blur);
        action?.Invoke(blur);
    }

    public void SetSelect(Action<IDictionary<string, object>> action)
    {
        FillSetting("select", select);
        action?.Invoke(select);
    }
}
